package com.XinYun.Library.modules.person.Service;

import com.XinYun.Library.modules.person.Dao.SQLDao;
import com.XinYun.Library.modules.person.Entity.User;
import com.XinYun.Library.utils.SqlUtils.DruidUtil;

import java.sql.ResultSet;


public class SqlServiceImpl implements UserService{
    public void change1(String uid,Object obj) {
        String Sql = "UPDATE user_info set mail = ? where uid = ?";
        {
            try {
                SQLDao.update(Sql,obj,uid);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }finally {
                //关闭资源
                DruidUtil.close();
            }
        }
    }
    public void change(String uid,Object obj) {
        String Sql = "UPDATE user_info set password = ? where uid = ?";
        {
            try {
                SQLDao.update(Sql,obj,uid);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }finally {
                //关闭资源
                DruidUtil.close();
            }
        }
    }

    @Override
    public String phone(String phone, String pwd,String uid) {
            SQLDao sql = new SQLDao();
            String Sql = "select password from user_info where uid = ?";
            ResultSet resultSet = null;
            String s ="0001";
            {
                try {
                    User user = null;
                    resultSet = sql.select(Sql,uid);
                    String userphone=resultSet.getString("phoneNumber");
                    String userPwd=resultSet.getString("password");
                    if(phone.equals(userphone)){return userPwd;}
                    else{return s;}
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }finally {
                    //关闭资源
                    DruidUtil.close(resultSet);
                }
            }
        }
    public static void picture(String url,String uid) throws Exception {
        String sql="update user_info set url = ? where uid = ?";
        SQLDao.update(sql,url,uid);
    }
}